<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>{$activity_info.jsonstr.activity_title}</title>
    <link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/womenday/css/wemenday.css{$Think.config.RESOURCE_VER}"/>
		
		<script src="{$Think.config.RESOURCEURL}wx_assets/womenday/js/remApp.js" type="text/javascript" charset="utf-8"></script>
		
		<script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="{$Think.config.RESOURCEURL}wx_assets/js/layer.m.js" type="text/javascript" charset="utf-8"></script>
		<script src="{$Think.config.RESOURCEURL}wx_assets/js/common.js{$Think.config.RESOURCE_VER}" type="text/javascript" charset="utf-8"></script>
		<script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js" type="text/javascript" charset="utf-8"></script>

		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
		<script src="{$Think.config.RESOURCEURL}wx_assets/womenday/js/wx_share.js{$Think.config.RESOURCE_VER}" type="text/javascript" charset="utf-8"></script>

		<script src="{$Think.config.RESOURCEURL}wx_assets/womenday/js/main.js{$Think.config.RESOURCE_VER}" type="text/javascript" charset="utf-8"></script>
		 <script type="text/javascript">
         var partake="{$partake_id}";
         checkPartake(partake);
     </script>
     <script type="text/javascript">
				//判断访问终端
			var browser={
			    versions:function(){
			        var u = navigator.userAgent, 
			            app = navigator.appVersion;
			        return {
			            trident: u.indexOf('Trident') > -1, //IE内核
			            presto: u.indexOf('Presto') > -1, //opera内核
			            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
			            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
			            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
			            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
			            android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
			            iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
			            iPad: u.indexOf('iPad') > -1, //是否iPad
			            webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
			            weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
			            qq: u.match(/\sQQ/i) == " qq" //是否QQ
			        };
			    }(),
			    language:(navigator.browserLanguage || navigator.language).toLowerCase()
			}
			</script>
</head>

<body>
    <div class="bg" data-bk="{$activity_info.jsonstr.activity_bg.src}">
        <img src="{$activity_info.jsonstr.activity_main.src}" class="theme" />
        <div class="container">
            <volist name="activity_info.jsonstr.activity_submit_tip.src" id="s">
            	<empty name="s">
            		<else />
                <div>
                    <img src="{$s}" />
                </div>
                <ul class="upload">
                    <li class="add">
                    </li>
                </ul>
               </empty>
            </volist>
            <div class='submitbtn'>
                <img src="{$activity_info.jsonstr.activity_submit_button.src}" />
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
var baseUrl="{$Think.config.SERVER_HOST}";
var is_need_sumbit_info="{$activity_info.jsonstr.is_need_sumbit_info}";
var picUrls=new Array();
if($.util.getParam("fromUserId"))
{
	var fromUserId=$.util.getParam("fromUserId");
}else {
	var fromUserId = "{$userId}";
}

var checkpic=function(){
		var result=true;
		$('.upload').each(function(){
			 var len=$(this).find('li').length;
			 if(len==1)
			 {
			 		result=false;
			 }	
		})
		if(!result)
		{
			layer.open({
				content:"请上传图片"
			})
		}
		return result;
}

var save_data=function(name,phone){



	$('[data-url]').each(function(){
		 var u=$(this).attr('data-url');
		 picUrls.push(u);
	})

	var save_data_link=buildUrl("json","photoShare","save_data",$.util.getParam("customerId"),{
		actId:$.util.getParamByObject("actId"),
		chanelId: $.util.getParamByObject("chanelId"),
		fromUserId:$.util.getParam("fromUserId")?$.util.getParam("fromUserId"):"",
		phone:phone?phone:"",
		name:name?name:"",
		picUrls:picUrls.join(",").toString()?picUrls.join(",").toString():""
	})

	$.ajax({
		url:save_data_link,
		type:"GET",
		dataType:"json",
		beforeSend:function(){
			layer.open({type: 2});
		},
		success:function(data){
			if(data.code==1)
			{
				var showlink=buildUrl("html","photoShare","show",$.util.getParam("customerId"),{
						actId:$.util.getParamByObject("actId"),
						chanelId: $.util.getParamByObject("chanelId"),
						partake_id:data.partake_id
				})

				window.location.href=showlink;
			}
			else 
			{
				layer.closeAll();
				layer.open({content:data.info})
			}
		}
	})
}

var getli=function(url){
	var li='<li data-url="'+url+'"><img src="'+url+'@320h_320w_1e_1c" /></li>';
	return li;
}


$('.add').on('click',function(){
	var parent=$(this).parent();
	// var img='http://oss.mboxone.com/20170227/image/3/1488200863211005.jpg';
	// 		var li=getli(img);
	// 		parent.prepend(li);
	uploadImage(function(data){
			var img=data.path;
			var li=getli(img);
			parent.prepend(li);
	});
})

var shareLink = buildUrl("html", "photoShare", "index", $.util.getParam("customerId"), {
    actId: $.util.getParamByObject("actId"),
    chanelId: $.util.getParamByObject("chanelId")
}, '&fromUserId=' + fromUserId)

var shareData = {
    "title": "{$activity_info.title}",
    "desc": "{$activity_info.description}",
    "link": baseUrl+shareLink,
    "imgUrl": "{$activity_info.picurl}",
    "pkg": {
        "appId": '{$pkg.appId}',
        "timestamp": {$pkg['timestamp']?$pkg['timestamp']:'""'},
        "nonceStr": '{$pkg.nonceStr}',
        "signature": '{$pkg.signature}'
    }
}
$(function(){
		wx_share.init(shareData);
		$('.submitbtn').on("click", function() {
			if(is_need_sumbit_info==1)
			{
				if(checkpic()){
				
			
		   		needInfo("{$activity_info.jsonstr.activity_info_bg.src}","{$activity_info.jsonstr.activity_info_submit.src}","{$Think.config.RESOURCEURL}wx_assets/womenday/img/close.png",function(data){
		   			if(typeof(data.username)=="undefined")
		   			{
		   				layer.open({
		   					content:"请输入姓名"
		   				})
		   				// alert("请输入姓名")
		   			}	else if(typeof(data.tel)=="undefined"){
		   				layer.open({
		   					content:"请输入手机号码"
		   				})
		   			} else {
		   				save_data(data.username,data.tel);
		   			}
		   			
		   		});
		   	}
			}
			else
			{
				if(checkpic()){
					save_data();
				}	 
			}
		});
})

var browserType=browser.versions;
if(browserType.android&&browserType.mobile&&!browserType.ios)
{
	var wHeight = window.innerHeight;   //获取初始可视窗口高度  
	window.addEventListener('resize', function(){       //监测窗口大小的变化事件  
	    var hh = window.innerHeight;     //当前可视窗口高度 
	    var viewTop = $(window).scrollTop();   //可视窗口高度顶部距离网页顶部的距离  
	    if(wHeight > hh){           //可以作为虚拟键盘弹出事件  
	        // $(".content").animate({scrollTop:viewTop+100});    //调整可视页面的位置  
	        $(".layermchild").css({
	        	"top":"-6rem"
	        })
	    }else{         //可以作为虚拟键盘关闭事件  
	        // $("content").animate({scrollTop:viewTop-100});  
	        $(".layermchild").css({
	        	"top":"auto"
	        })
	    }  
	    wHeight = hh;  
	}); 
}

</script>

</html>
